"""
钱包相关 Pydantic 模型
"""
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
from app.models.wallet import TransactionType, TransactionStatus


# ==================== Wallet ====================

class WalletBase(BaseModel):
    """钱包基础模型"""
    balance: float = Field(default=0.0, description="余额")
    frozenAmount: float = Field(default=0.0, description="冻结金额")
    totalRecharge: float = Field(default=0.0, description="累计充值")
    totalWithdraw: float = Field(default=0.0, description="累计提现")
    totalSpent: float = Field(default=0.0, description="累计消费")


class WalletResponse(WalletBase):
    """钱包响应模型"""
    id: str
    userId: str
    createdAt: Optional[str] = None
    updatedAt: Optional[str] = None
    
    class Config:
        from_attributes = True


# ==================== Transaction ====================

class TransactionBase(BaseModel):
    """交易记录基础模型"""
    type: TransactionType = Field(description="交易类型")
    amount: float = Field(description="交易金额")
    description: Optional[str] = Field(None, description="交易描述")
    relatedId: Optional[str] = Field(None, description="关联ID")
    relatedType: Optional[str] = Field(None, description="关联类型")


class RechargeRequest(BaseModel):
    """充值请求"""
    amount: float = Field(..., gt=0, description="充值金额")
    paymentMethod: str = Field(..., description="支付方式: wechat, alipay")


class WithdrawRequest(BaseModel):
    """提现请求"""
    amount: float = Field(..., gt=0, description="提现金额")
    bankAccount: Optional[str] = Field(None, description="银行账号")
    bankName: Optional[str] = Field(None, description="银行名称")


class TransferRequest(BaseModel):
    """转账请求"""
    toUserId: str = Field(..., description="接收方用户ID")
    amount: float = Field(..., gt=0, description="转账金额")
    remark: Optional[str] = Field(None, description="备注")


class TransactionResponse(TransactionBase):
    """交易记录响应模型"""
    id: str
    walletId: str
    userId: str
    balanceBefore: float
    balanceAfter: float
    status: TransactionStatus
    paymentMethod: Optional[str] = None
    paymentChannelOrderNo: Optional[str] = None
    remark: Optional[str] = None
    createdAt: Optional[str] = None
    completedAt: Optional[str] = None
    
    class Config:
        from_attributes = True


class TransactionFilterParams(BaseModel):
    """交易记录筛选参数"""
    type: Optional[TransactionType] = Field(None, description="交易类型")
    status: Optional[TransactionStatus] = Field(None, description="交易状态")
    startDate: Optional[str] = Field(None, description="开始日期 YYYY-MM-DD")
    endDate: Optional[str] = Field(None, description="结束日期 YYYY-MM-DD")
    page: int = Field(1, ge=1, description="页码")
    pageSize: int = Field(10, ge=1, le=100, description="每页数量")

